import React from 'react'
import {HashRouter,Route,Switch,Redirect} from 'react-router-dom'
import Login from '../views/login'
import { getToken } from '../utils/auth'
import Layout from '../Layout'

const Router=()=>{
    let token = getToken()
    return (
        // Provider的孩子
        <HashRouter>
            <Switch>
                <Route 
                    path="/login" 
                    component={Login}
                     />
                <Route 
                    exact
                    path="/" 
                    render={()=>{
                        if(!token){
                            return <Redirect to="/login" />
                        }
                        else {
                            console.log('已经登录')
                            return <Layout />
                        }
                    }} />
            </Switch>
        </HashRouter>
    )
}

export default Router